package com.jn.rxjava.views;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jn.rxjava.R;

public class MainActivity extends AppCompatActivity {
    private EditText newsUrlEditText, weatherUrlEditText;
    private Button newsSubmitButton, weatherSubmitButton;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        newsUrlEditText = findViewById(R.id.news_url_edit_text);
        newsSubmitButton = findViewById(R.id.news_submit_button);
        weatherUrlEditText = findViewById(R.id.weather_url_edit_text);
        weatherSubmitButton = findViewById(R.id.weather_submit_button);

        newsSubmitButton.setOnClickListener(v -> {
            String url = newsUrlEditText.getText().toString().trim();
            if (url.isEmpty()) {
                Toast.makeText(this, "请输入新闻网址", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent = new Intent(MainActivity.this, NewsActivity.class);
            intent.putExtra("url", url);
            startActivity(intent);
        });

        weatherUrlEditText = findViewById(R.id.weather_url_edit_text);
        weatherSubmitButton = findViewById(R.id.weather_submit_button);

        weatherSubmitButton.setOnClickListener(v -> {
            String url = weatherUrlEditText.getText().toString().trim();
            if (url.equals("https://apis.juhe.cn/simpleWeather")) {
                Toast.makeText(this, "请输入正确的天气网址", Toast.LENGTH_SHORT).show();
                return;
            }
            Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
            startActivity(intent);
        });
    }


    }


